/**
 * 作者: hxl
 * 日期: 2025-03-15 16:04:18
 * 备注: 用户跨服限时充值任务表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserCrossRechargeActTask;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserCrossRechargeActTaskModel extends BaseModel implements Model {
    public static final String LISTKEY = "act_list_key.task_type";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = true;// 是否需要额外的有序列表

    protected long id; // id
    protected long userId; // 玩家id
    protected long round; // 活动轮次
    protected int configId; // 活动流配置id
    protected int taskType; // 任务类型
    protected long curP; // 当前进度
    protected long resetTime; // 重置时间
    protected String actListKey = ""; // 组合key (userId_configId)
    protected long rechargeTime; // 充值时间

    public void reset() {
    }

    protected String getKey() {
        return "UserCrossRechargeActTask." + actListKey + "." + taskType;
    }

    protected String getListKey() {
        return "UserCrossRechargeActTask." + actListKey;
    }

    protected String getListItemKey() {
        return taskType + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_cross_recharge_act_task"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // id
        obj.put("userId", userId); // 玩家id
        obj.put("round", round); // 活动轮次
        obj.put("configId", configId); // 活动流配置id
        obj.put("taskType", taskType); // 任务类型
        obj.put("curP", curP); // 当前进度
        obj.put("resetTime", resetTime); // 重置时间
        obj.put("actListKey", actListKey); // 组合key (userId_configId)
        obj.put("rechargeTime", rechargeTime); // 充值时间
        return obj;
    }

    public PBUserCrossRechargeActTask.Builder takeInitBuilder() {
        PBUserCrossRechargeActTask.Builder sb = PBUserCrossRechargeActTask.newBuilder();
        if (round != 0) {
            sb.setRound(round);
        }
        if (configId != 0) {
            sb.setConfigId(configId);
        }
        if (taskType != 0) {
            sb.setTaskType(taskType);
        }
        if (curP != 0) {
            sb.setCurP(curP);
        }
        return sb;
    }

    public PBUserCrossRechargeActTask.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserCrossRechargeActTask.Builder sb = PBUserCrossRechargeActTask.newBuilder();
        if (isFieldUpdate("round")) {
            sb.setRound(round);
        }
        if (isFieldUpdate("configId")) {
            sb.setConfigId(configId);
        }
        if (isFieldUpdate("taskType")) {
            sb.setTaskType(taskType);
        }
        if (isFieldUpdate("curP")) {
            sb.setCurP(curP);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getUserId() {
        return userId;
    }

    public void putUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            updateRedisHashField(getKey(), "userId", this.userId);
        }
    }

    public void addUserId(long value) {
        this.userId += value;
        updateRedisHashField(getKey(), "userId", this.userId);
    }

    public long getRound() {
        return round;
    }

    public void putRound(long round) {
        if (this.round != round) {
            this.round = round;
            updateRedisHashField(getKey(), "round", this.round);
        }
    }

    public void addRound(long value) {
        this.round += value;
        updateRedisHashField(getKey(), "round", this.round);
    }

    public int getConfigId() {
        return configId;
    }

    public void putConfigId(int configId) {
        if (this.configId != configId) {
            this.configId = configId;
            updateRedisHashField(getKey(), "configId", this.configId);
        }
    }

    public void addConfigId(int value) {
        this.configId += value;
        updateRedisHashField(getKey(), "configId", this.configId);
    }

    public int getTaskType() {
        return taskType;
    }

    public void putTaskType(int taskType) {
        if (this.taskType != taskType) {
            this.taskType = taskType;
            updateRedisHashField(getKey(), "taskType", this.taskType);
        }
    }

    public void addTaskType(int value) {
        this.taskType += value;
        updateRedisHashField(getKey(), "taskType", this.taskType);
    }

    public long getCurP() {
        return curP;
    }

    public void putCurP(long curP) {
        if (this.curP != curP) {
            this.curP = curP;
            updateRedisHashField(getKey(), "curP", this.curP);
        }
    }

    public void addCurP(long value) {
        this.curP += value;
        updateRedisHashField(getKey(), "curP", this.curP);
    }

    public long getResetTime() {
        return resetTime;
    }

    public void putResetTime(long resetTime) {
        if (this.resetTime != resetTime) {
            this.resetTime = resetTime;
            updateRedisHashField(getKey(), "resetTime", this.resetTime);
        }
    }

    public void addResetTime(long value) {
        this.resetTime += value;
        updateRedisHashField(getKey(), "resetTime", this.resetTime);
    }

    public String getActListKey() {
        return actListKey;
    }

    public void putActListKey(String actListKey) {
        if (!this.actListKey.equals(actListKey)) {
            this.actListKey = actListKey;
            updateRedisHashField(getKey(), "actListKey", this.actListKey);
        }
    }

    public long getRechargeTime() {
        return rechargeTime;
    }

    public void putRechargeTime(long rechargeTime) {
        if (this.rechargeTime != rechargeTime) {
            this.rechargeTime = rechargeTime;
            updateRedisHashField(getKey(), "rechargeTime", this.rechargeTime);
        }
    }

    public void addRechargeTime(long value) {
        this.rechargeTime += value;
        updateRedisHashField(getKey(), "rechargeTime", this.rechargeTime);
    }

}